package cj.web.admin.dao;
/*
 *  
 *  
*/
import java.util.List;
import net.paoding.rose.jade.annotation.DAO;
import net.paoding.rose.jade.annotation.SQL;
import net.paoding.rose.jade.annotation.SQLParam;
import cj.web.admin.domain.Goods;

/**
 * 
 * @author 
 *
 */
@DAO
public interface GoodsDAO{
	
	@SQL("SELECT * FROM Goods WHERE deleteFlag=1  #if(:t.category!=null ){AND category LIKE '%##(:t.category)%'} #if(:t.name!=null ){AND name LIKE '%##(:t.name)%'} #if(:t.order==null ){ ORDER BY updateAt DESC } #if(:t.order=='goodsPrice' ){ ORDER BY updateAt DESC,goodsPrice ASC } #if(:t.order=='couponPrice' ){ ORDER BY updateAt DESC,couponPrice ASC }  LIMIT :t.start,:t.length ")
    List<Goods> query(@SQLParam("t") Goods goods);
	
	@SQL("SELECT count(1) FROM Goods WHERE deleteFlag=1  #if(:t.category!=null ){AND category LIKE '%##(:t.category)%'} #if(:t.name!=null ){AND name LIKE '%##(:t.name)%'} ")
    int querySize(@SQLParam("t") Goods goods);
	
	@SQL("SELECT * FROM Goods WHERE deleteFlag=1 and couponPrice < 10 #if(:t.category!=null ){AND category LIKE '%##(:t.category)%'} #if(:t.name!=null ){AND name LIKE '%##(:t.name)%'} #if(:t.order==null ){ ORDER BY updateAt DESC } #if(:t.order=='goodsPrice' ){ ORDER BY updateAt DESC,goodsPrice ASC } #if(:t.order=='couponPrice' ){ ORDER BY updateAt DESC,couponPrice ASC }  LIMIT :t.start,:t.length ")
    List<Goods> queryNine(@SQLParam("t") Goods goods);
	
	@SQL("SELECT count(1) FROM Goods WHERE deleteFlag=1 and couponPrice < 10 #if(:t.category!=null ){AND category LIKE '%##(:t.category)%'} #if(:t.name!=null ){AND name LIKE '%##(:t.name)%'} ")
    int queryNineSize(@SQLParam("t") Goods goods);
    
    @SQL("select count(1) from Goods where id=:1")
    int querySizeById(String id);
    
    @SQL("select * from Goods where id=:1")
    Goods queryById(String id);
    
    @SQL("INSERT INTO Goods ("
    		        		+ "id,"
			        		+ "name,"
			        		+ "images,"
			        		+ "detailUrl,"
			        		+ "category,"
			        		+ "tkUrl,"
			        		+ "goodsPrice,"
			        		+ "sellCount,"
			        		+ "percentage,"
			        		+ "brokerage,"
			        		+ "sellww,"
			        		+ "sellId,"
			        		+ "sellName,"
			        		+ "type,"
			        		+ "couponId,"
			        		+ "couponCount,"
			        		+ "couponSurplus,"
			        		+ "couponDescs,"
			        		+ "couponStartAt,"
			        		+ "couponEndAt,"
			        		+ "couponUrl,"
			        		+ "goodsCouponUrl,"
			        		+ "couponPrice,"
			        		+ "deleteFlag,"
			        		+ "createUser,"
			        		+ "createAt,"
			        		+ "updateUser,"
			        		+ "updateAt"
							+") VALUES ("
							+ ":t.id,"
							+ ":t.name,"
							+ ":t.images,"
							+ ":t.detailUrl,"
							+ ":t.category,"
							+ ":t.tkUrl,"
							+ ":t.goodsPrice,"
							+ ":t.sellCount,"
							+ ":t.percentage,"
							+ ":t.brokerage,"
							+ ":t.sellww,"
							+ ":t.sellId,"
							+ ":t.sellName,"
							+ ":t.type,"
							+ ":t.couponId,"
							+ ":t.couponCount,"
							+ ":t.couponSurplus,"
							+ ":t.couponDescs,"
							+ ":t.couponStartAt,"
							+ ":t.couponEndAt,"
							+ ":t.couponUrl,"
							+ ":t.goodsCouponUrl,"
							+ ":t.couponPrice,"
							+ "1,"
							+ ":t.createUser,"
							+ "now(),"
							+ ":t.updateUser,"
							+ "now()"
					+")")
    void create(@SQLParam("t") Goods goods);
    
	
	@SQL("UPDATE Goods SET "
	    			        + "name=:t.name,"
	    			        + "images=:t.images,"
	    			        + "detailUrl=:t.detailUrl,"
	    			        + "category=:t.category,"
	    			        + "tkUrl=:t.tkUrl,"
	    			        + "goodsPrice=:t.goodsPrice,"
	    			        + "sellCount=:t.sellCount,"
	    			        + "percentage=:t.percentage,"
	    			        + "brokerage=:t.brokerage,"
	    			        + "sellww=:t.sellww,"
	    			        + "sellId=:t.sellId,"
	    			        + "sellName=:t.sellName,"
	    			        + "type=:t.type,"
	    			        + "couponId=:t.couponId,"
	    			        + "couponCount=:t.couponCount,"
	    			        + "couponSurplus=:t.couponSurplus,"
	    			        + "couponDescs=:t.couponDescs,"
	    			        + "couponStartAt=:t.couponStartAt,"
	    			        + "couponEndAt=:t.couponEndAt,"
	    			        + "couponUrl=:t.couponUrl,"
	    			        + "goodsCouponUrl=:t.goodsCouponUrl,"
	    			        + "couponPrice=:t.couponPrice,"
	    			        + "updateUser=:t.updateUser,"
	    			        + "updateAt=now()"
    						+ " WHERE id=:t.id")
    void update(@SQLParam("t") Goods goods);
	
    @SQL("UPDATE Goods SET deleteFlag=0 WHERE id=:1")
    void deleteById(int id);
}